import java.util.Scanner;
public class Phanso {
	Phanso t;
	int TS;
	int MS;
	public void setTS(int k)
	{
		TS=k;
	}
	
	public int getTS()
	{
		return TS;
	}
	public void setMS(int k)
	{
		MS=k;
	}
	public int getMS()
	{
		return MS;
	}
	public void hienthi()
	{
		System.out.println(TS+"/"+MS);
	}
	public Phanso()
	{
		
	}
	public Phanso(int ts,int ms)
	{
		TS=ts;
		MS=ms;
	}
	int ucln(int a,int b)
	{
		while (a !=b)
        {
            if(a>b)
                a=a-b;
            else
                b=b-a;
        }
        return a;
	}
	int bcnn(int a,int b)
	{
		int c=ucln(a,b);
		return (a*b)/c;
	}
	void toigian()
	{
		int d=ucln(TS,MS);
		TS=TS/d;
		MS=MS/d;
	}
	public void nghichdao()
	{
		int d=TS;
		TS=MS;
		MS=d;
	}
	public void cong(Phanso x)
	{
		
		int d=bcnn(MS,x.getMS());
		this.setTS(d*TS/MS+d*x.getTS()/x.getMS());
		this.setMS(d);
		toigian();
		System.out.println(TS+"/"+MS); 
	}
	public void tru(Phanso x)
	{
		
		int d=bcnn(MS,x.getMS());
		this.setTS(d*TS/MS-d*x.getTS()/x.getMS());
		this.setMS(d);
		toigian();
		System.out.println(TS+"/"+MS); 
	}
	public void nhan(Phanso x)
	{
		
	
		this.setTS(TS*x.getTS());
		this.setMS(MS*x.getMS());
		toigian();
		System.out.println(TS+"/"+MS); 
	}
	public void chia(Phanso x)
	{
		
		nghichdao();
		this.setTS(TS*x.getTS());
		this.setMS(MS*x.getMS());
		toigian();
		System.out.println(TS+"/"+MS); 
	}
	public int compareTo (Phanso o) {
		
		if(this.getMS()==o.getMS())
			{
			if(this.getTS()>o.getTS())
				return 1;
			else 
			if(this.getTS()==o.getTS())
				return 0;
			else return -1;
			}
		else 
		{
			int d=bcnn(this.getMS(),o.getMS());
			if(this.getTS()*d/this.getMS()>o.getTS()*d/o.getMS())
				return 1;
			else 
				if(this.getTS()==o.getTS())
				return 0;
				else return -1;
			
		}
	}
	public void nhap()
	{	
		Scanner scan1=new Scanner(System.in);
		System.out.println("Nhap tu so ");
		int a2=scan1.nextInt();
		System.out.println("Nhap mau so ");
		int b2=scan1.nextInt();
		setTS(a2);
		setMS(b2);
	
	}
		
		
	public static void main(String[] args)
	{
		
		
		Scanner scan=new Scanner(System.in);
		
		Phanso ps1=new Phanso();
		Phanso ps2=new Phanso();
		int a,b;
		System.out.println("Nhap tu so phan so thu nhat");
		a=scan.nextInt();
		System.out.println("Nhap mau so phan so thu nhat");
		b=scan.nextInt();
		ps1.setTS(a);
		ps1.setMS(b);
		System.out.println("Phan so  la ");
		ps1.hienthi();
		int a1,b1;
		System.out.println("Nhap tu so phan so thu nhat");
		a1=scan.nextInt();
		System.out.println("Nhap mau so phan so thu nhat");
		b1=scan.nextInt();
		ps2.setTS(a1);
		ps2.setMS(b1);
		System.out.println("Phan so la ");
		ps2.hienthi();
		System.out.println("Phan so nghich dao cua phan so thu nhat la ");
		ps1.nghichdao();
		ps1.hienthi();
		ps1.nghichdao();
		System.out.println("Phan so nghich dao cua phan so thu hai la ");
		ps2.nghichdao();
		ps2.hienthi();
		ps2.nghichdao();
		System.out.println("phan so 1 cong phan so 2 la");
		 
		ps1.cong(ps2);
		System.out.println("Gia tri 2 phan so sau khi thuc hien phep cong la");
		ps1.hienthi();
		ps2.hienthi();
		System.out.println("phan so 1 tru phan so 2 la");
		 
		ps1.tru(ps2);
		System.out.println("Gia tri 2 phan so sau khi thuc hien phep tru la");
		ps1.hienthi();
		ps2.hienthi();
		System.out.println("phan so 1 nhan phan so 2 la");
		 
		ps1.nhan(ps2);
		System.out.println("Gia tri 2 phan so sau khi thuc hien phep nhan la");
		ps1.hienthi();
		ps2.hienthi();
		System.out.println("phan so 1 chia phan so 2 la");
		 
		ps1.chia(ps2);
		System.out.println("Gia tri 2 phan so sau khi thuc hien phep chia la");
		ps1.hienthi();
		ps2.hienthi();
		System.out.println("Nhap 1 day cac phan so");
		Phanso[] arr=new Phanso[3];
		for(int i=0;i<3;i++)
		{
			arr[i]=new Phanso();
			arr[i].nhap();
			
		}
		System.out.println("Cac phan so khi chua sap xep la :");
		for(int i=0;i<3;i++)
		{
			arr[i].hienthi();
		}
		
		java.util.Arrays.sort(arr);
		System.out.println("cac phan so sau khi dc sap xep la");
		for(int i=0;i<3;i++)
		{
			arr[i].hienthi();
		}
	}

}
